//
//  Top2ViewController.m
//  必争医疗
//
//  Created by 8号球 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Top2ViewController.h"
#import "DoctorViewController.h"

@interface Top2ViewController () <UITableViewDataSource, UITableViewDelegate>

@end

@implementation Top2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.Hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.view.backgroundColor = [UIColor grayColor];
    [self creatB2];
    [self creatB1];
    [self creatView];
    [self creatButtonItem];
}
- (void)creatView
{
    UIButton *b1 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *b2 = [UIButton buttonWithType:UIButtonTypeCustom];
    b1.frame = CGRectMake(0, 65, 375.0 / 2 - 0.5, 44);
    b2.frame = CGRectMake(375.0 / 2 + 0.5, 65, 375.0 / 2 - 0.5, 44);
    b1.backgroundColor = [UIColor whiteColor];
    b2.backgroundColor = [UIColor whiteColor];
    [b1 addTarget:self action:@selector(B1:) forControlEvents:UIControlEventTouchUpInside];
    [b2 addTarget:self action:@selector(B2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:b1];
    [self.view addSubview:b2];
    UITableView *tb = [[[UITableView alloc]initWithFrame:CGRectMake(0, 110, 375, 667 - 110)]autorelease];
    tb.tag = 21;
    tb.dataSource = self;
    tb.delegate = self;
    tb.rowHeight = 100;
    [self.view addSubview:tb];
}
- (void)creatB1
{
    UIView *v = [[[UIView alloc]initWithFrame:CGRectMake(0, 110, 375, 667 - 110)]autorelease];
    UITableView *tb = [[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667 - 110)]autorelease];
    v.tag = 24;
    tb.tag = 22;
    tb.dataSource = self;
    tb.delegate = self;
    tb.rowHeight = 30;
    tb.bounces = NO;
    [v addSubview:tb];
    [self.view addSubview:v];
}
- (void) B1 :(id)sender
{
    NSArray *array = self.view.subviews;
    if ([array lastObject] == [self.view viewWithTag:24])
    {
        [self.view bringSubviewToFront:[self.view viewWithTag:24]];
        [self.view bringSubviewToFront:[self.view viewWithTag:21]];
    }
    else
    {
        [self.view bringSubviewToFront:[self.view viewWithTag:21]];
        [self.view bringSubviewToFront:[self.view viewWithTag:24]];
    }
}
- (void)creatB2
{
    UIView *b = [[[UIView alloc]initWithFrame:CGRectMake(0, 110, 375, 667 - 110)]autorelease];
    UIView *v = [[[UIView alloc]initWithFrame:CGRectMake(0, 90, 375, 667 - 110 - 90)]autorelease];
    v.backgroundColor = [UIColor grayColor];
    v.alpha = 0.5;
    UITableView *tb = [[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 90)]autorelease];
    b.tag = 25;
    tb.tag = 23;
    tb.dataSource = self;
    tb.delegate = self;
    tb.rowHeight = 30;
    tb.bounces = NO;
    [b addSubview:v];
    [b addSubview:tb];
    [self.view addSubview:b];
}
- (void) B2 :(id)sender
{
    NSArray *array = self.view.subviews;
    if ([array lastObject] == [self.view viewWithTag:25])
    {
        [self.view bringSubviewToFront:[self.view viewWithTag:25]];
        [self.view bringSubviewToFront:[self.view viewWithTag:21]];
    }
    else
    {
        [self.view bringSubviewToFront:[self.view viewWithTag:21]];
        [self.view bringSubviewToFront:[self.view viewWithTag:25]];
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (tableView.tag) {
        case 21:
        {
            return 10;
        }
            break;
        case 22:
        {
            return 20;
        }
            break;
        case 23:
        {
            return 3;
        }
        default:
            break;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (tableView.tag) {
        case 21:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"21"];
            if (!cell)
            {
                cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"21"]autorelease];
            }
            [cell.imageView setImage:[UIImage imageNamed:@"3.png"]];
            cell.textLabel.text = @"???";
            cell.detailTextLabel.text = @"???";
            return cell;
        }
            break;
        case 22:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"22"];
            if (!cell)
            {
                cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"22"]autorelease];
            }
            cell.textLabel.text = @"???";
            return cell;
        }
            break;
        case 23:
        {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"23"];
            if (!cell)
            {
                cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"23"]autorelease];
            }
            cell.textLabel.text = @"???";
            return cell;
        }
        default:
            break;
    }
    return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DoctorViewController *doc = [[[DoctorViewController alloc]init]autorelease];
    [self.navigationController pushViewController:doc animated:YES];
}
- (void)creatButtonItem
{
    UIButton *bl = [UIButton buttonWithType:UIButtonTypeCustom];
    [bl setTitle:@"今日义诊" forState:UIControlStateNormal];
    [bl setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    bl.frame = CGRectMake(0, 0, 80, 30);
    [bl addTarget:self action:@selector(L:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *br = [UIButton buttonWithType:UIButtonTypeCustom];
    [br setTitle:@"帮助" forState:UIControlStateNormal];
    [br setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    br.backgroundColor = [UIColor greenColor];
    br.frame = CGRectMake(0, 0, 60, 30);
    [br addTarget:self action:@selector(R:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *left = [[[UIBarButtonItem alloc]initWithCustomView:bl]autorelease];
    UIBarButtonItem *right = [[[UIBarButtonItem alloc]initWithCustomView:br]autorelease];
    self.navigationItem.leftBarButtonItem = left;
    self.navigationItem.rightBarButtonItem = right;
}
- (void)L :(id)sender
{
    [self.navigationController.navigationBar setHidden:YES];
    [self.tabBarController.tabBar setHidden:NO];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)R :(id)sender
{
    UILabel *l1 = [[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 30)]autorelease];
    l1.backgroundColor = [UIColor whiteColor];
    l1.text = @"点击提问";
    UILabel *l2 = [[[UILabel alloc]initWithFrame:CGRectMake(500, 500, 100, 30)]autorelease];
    l2.backgroundColor = [UIColor whiteColor];
    l2.text = @"填写问题";
    UIButton *b = [[[UIButton alloc]initWithFrame:CGRectMake(125, 500, 100, 30)]autorelease];
    [b setTitle:@"我知道了" forState:UIControlStateNormal];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:l1, @"1", l2, @"2", b, @"3", nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"HELP" object:self userInfo:dic];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
